<template>
  <div>
    <!--工具类-->

    <Row style="text-align: left" v-model="status.modalSearch.isShow">
      <i-col span="24">
        <Row v-has=tRole.ORDER_1_101 style="margin-top: 0.8rem" class="y_query_right">
          <i-col span="24" class="operation_item y_query_right" :xs="{ span: 24, offset: 0 }" :sm="{ span: 24, offset:0 }">
            <Cascader :data="categoryList" @on-change="categorySelected" change-on-select
                      placeholder="产品分类" class="y_condition" style="text-align: left; max-width: 200px;"></Cascader>

<!--          </i-col>-->
<!--          <i-col span="17" class="operation_item">-->
            <Input v-model.trim="params.searchParams.productCode" placeholder="产品编号" clearable
                   class="modal_form_input y_condition"></Input>
            <DatePicker type="datetime"  :options="dateRange" @on-change="chooseStartDate"
                        placement="bottom-end" placeholder="选择起始日期时间" class="modal_form_input y_condition" format="yyyy-MM-dd"></DatePicker>
            <DatePicker type="datetime"  :options="dateRange" @on-change="chooseEndDate"
                        placement="bottom-end" placeholder="选择结束日期时间" class="modal_form_input y_condition" format="yyyy-MM-dd"></DatePicker>
            <Button type="primary" style="margin-right: 10px" icon="ios-search" @click="search" class="y_condition">查询</Button>
          </i-col>
        </Row>
      </i-col>
    </Row>

    <!--表格和分页-->
<!--    <Table stripe border :columns="tableTitles" :data="productOrderList" ref="orderList"
           class="table_css"
           no-data-text="暂无数据或者购物车数量为0"></Table>-->


    <List border class="data-list">
      <template v-if="productOrderList.length == 0">
        <ListItem class="list-item">
          <div style="width: 100%; text-align: center; color: #ccc;">暂无数据</div>
        </ListItem>
      </template>
      <template v-else>
        <ListItem v-for="(item, index) in productOrderList" :key="index" class="list-item">
          <Row style="width: 100%;">
            <Col :span="3" :xxl="3" :xl="4" :lg="5" :md="6" :sm="8" :xs="10">
              <div style="width: 130px; text-align: center; margin: 0 auto;" @click="showBigImage(getProductImg(item))">
                <img :src="getProductImg(item)" style="max-width: 100%;"/>
              </div>
            </Col>
            <Col :span="21" :xxl="21" :xl="20" :lg="19" :md="18" :sm="16" :xs="14" style="padding-left: 0.5rem">
              <div class="item-top">
                <KeyValueView title="产品编码">
                  <a :href="$tiyProductUrl(item.productCode)" target="_blank">{{item.productCode}}</a>
                </KeyValueView>
                <KeyValueView title="产品名称" :value="item.productName"></KeyValueView>
              </div>
              <div class="item-top">
                <KeyValueView title="购物车留存量" :value="item.total"></KeyValueView>
              </div>
            </Col>
          </Row>
        </ListItem>
      </template>
    </List>
    <div style="float: right; margin-top: 20px;">
      <Page :total="tPage.total" :page-size="tPage.stepNumber" :current="tPage.currentPage" @on-change="changePage"
            @on-page-size-change="sizeChange" :page-size-opts="[40,60,80,120]"
            show-sizer show-elevator/>
    </div>

    <Modal
      v-model="status.modalImage.isShow"
      title=""
      :styles="{align:'center'}"
      :scrollable=true>
      <div slot="footer"></div>
      <div align="center"><Img :src="status.modalImage.url" style="max-width: 300px" /></div>
    </Modal>

  </div>
</template>

<!--javascript 代码-->
<script>
  import ICol from "../../../node_modules/view-design/src/components/grid/col";
  import tiyData from "./js/cart/data"
  import {getProductCommonData, createCategoryList, isEmpty} from "../js/commonUtils"

  import {
    init,
    webList,
  } from "./js/cart/funs"
  import Operation from "view-design/src/components/transfer/operation";
  import KeyValueView from "../widgets/KeyValueView";

  export default {
    components: {KeyValueView, Operation, ICol},
    data(){
      return {
        yunPath: this.$store.getters.imgPrefix,
        tRole:{//权限
          ORDER_1_101:"ORDER-1-101",
        },
        tPage: tiyData.tPage,
        status: tiyData.tStatus,
        params: tiyData.tParams,
        //搜索条件
        searchParams: tiyData.tParams.searchParams,
        tData: tiyData.tData,
        productOrderList: tiyData.tData.productOrderList,
        classificationList: tiyData.tData.classificationList,
        categoryList: tiyData.tData.categoryList,
        dateRange: tiyData.tData.dateRange,
        tableTitles:tiyData.tableTitles(this),
      }
    },
    computed : {

    },
    methods: {

      search(){
        tiyData.tPage.currentPage = 1;
        webList(this, tiyData);
      },
      changePage(page){
        tiyData.tPage.currentPage = page;
        webList(this, tiyData);
      },
      sizeChange(p){
        tiyData.tPage.stepNumber = p;
        webList(this, tiyData);
      },
      categorySelected(value, selectedData){
        //选择分类后的条件如果改变后要修改productBatchSequenceView方法里的判断条件
        if (0 < selectedData.length) {
          tiyData.tParams.searchParams.categoryCode = selectedData[selectedData.length - 1].value;
          tiyData.tParams.searchParams.categoryLevel = selectedData[selectedData.length - 1].level;
        } else {
          tiyData.tParams.searchParams.categoryCode = '';
          tiyData.tParams.searchParams.categoryLevel = 1;
        }

      },
      chooseStartDate(date){
        tiyData.tParams.searchParams.startCreatedate = date+' 00:00:00';
      },
      chooseEndDate(date){
        tiyData.tParams.searchParams.endCreatedate = date+' 23:59:59';
      },
      getProductImg(item) {
        let imageUrl = item.productImg;
        if(isEmpty(imageUrl)) {
          return "";
        }
        return this.yunPath + imageUrl;
      },
      showBigImage(imageUrl) {
        status.modalImage.url = imageUrl;
        status.modalImage.isShow = true;
      },
    },
    mounted(){
      init(this, tiyData);
        let types = [];
        types.push(3); //列表只查询分类
        getProductCommonData(this, tiyData.tData.categoryList, types, false, createCategoryList);
    }
  }
</script>

<!--css样式-->
<style scoped lang="less">
@import  (once,optional)  "../css/base.less";

  .table_css {
    margin: 1rem 0px;
  }

  .modal_newuser_form {
    padding-left: 60px;
    padding-top: 30px;
    padding-bottom: 30px;
  }

  .modal_form_input {
    max-width: 200px;
    margin-right: 10px;

  }

  .order_product_div {
    margin-top: 1rem;

  }
  .order_product_row {
    background: #f3f3f6;
    padding: 1rem;
    border: .0625rem solid #dbdbdb;
    border-bottom-style: none;
  }

  .key{
    .tiy_key;
  }

.data-list {
  margin: 1rem 0rem;
  line-height: 25px;
  .list-item {
    .flex-colum-wrap;
    justify-items: left;
    align-items: start;
    .item-checkbox {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      vertical-align: top;
    }
    .item-img {
      width: 130px;
      text-align: center;
      display: inline-block;
    }
    .item-top{
      width: 100%;
      margin-bottom: 5px;
      .flex-row-wrap;
      justify-content: left;
    }
    .item-content {
      margin-bottom: 35px;
      text-align: left;
    }
    .item-bottom{
      //position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      display: block;
      //padding: 0 1rem 0.5rem 0;
      text-align: right;
      button {
        margin-left: 0.5rem;
      }
    }
  }
}
</style>
